﻿using MaterialDesignThemes.Wpf;
using Prism.Mvvm;

namespace Compass.Wpf.ViewModels.Dialogs;

public class DateViewModel : BindableBase, IDialogHostAware
{

    public DateViewModel()
    {
        SaveCommand = new DelegateCommand(Save);
        CancelCommand = new DelegateCommand(Cancel);
    }

    public DelegateCommand SaveCommand { get; set; }
    public DelegateCommand CancelCommand { get; set; }


    #region 属性
    public string DialogHostName { get; set; }
    private string title;
    public string Title
    {
        get => title;
        set { title = value; RaisePropertyChanged(); }
    }
    private DateTime date;
    public DateTime Date
    {
        get => date;
        set { date = value; RaisePropertyChanged(); }
    }
    #endregion

    private void Save()
    {
        if (!DialogHost.IsDialogOpen(DialogHostName)) return;
        var param = new DialogParameters { { "Date", Date } };
        //保存时传递参数
        DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.OK, param));
    }
    private void Cancel()
    {
        if (DialogHost.IsDialogOpen(DialogHostName))
        {
            DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
        }
    }

    public void OnDialogOpen(IDialogParameters parameters)
    {
        if (parameters.ContainsKey("Title")) Title = parameters.GetValue<string>("Title");
        if (parameters.ContainsKey("Date")) Date = parameters.GetValue<DateTime>("Date");
    }
}